package com.liu.communitysystemend.module.room.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liu.communitysystemend.module.room.domain.RoomDto;
import com.liu.communitysystemend.module.room.service.RoomService;
import com.liu.communitysystemend.module.room.domain.Room;
import com.liu.communitysystemend.module.user.domain.User;
import com.liu.communitysystemend.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liu
 * @create 2023-02-28 17:39
 */

@RestController
@RequestMapping("/api/room")
public class RoomController {
    @Autowired
    private RoomService roomService;


    @ApiOperation("获取房间信息")
    @GetMapping("/get/{id}")
    public Result<Room> getUser(@PathVariable("id")String id){
        return Result.success(roomService.getUserById(id));
    }

    @ApiOperation("更新房间信息")
    @PostMapping("modify")
    public Result<Room> save(@RequestBody Room room) {
        return Result.success(roomService.update(room));
    }

    @ApiOperation("添加房间信息")
    @PostMapping("add")
    public Result<Room> add(@RequestBody Room room){
        return Result.success(roomService.add(room));
    }

    @ApiOperation("查询房间列表(分页)")
    @PostMapping("page")
    public Result<Page<Room>> getPage(@RequestBody Room room) {
        return Result.success(roomService.getPage(room));
    }

    @GetMapping("delete/{id}")
    @ApiOperation("删除用户")
    public Result deleteById(@PathVariable("id") String id){
        return roomService.deleteById(id)>0 ? Result.success():Result.failed();
    }


    @ApiOperation("获取房间列表")
    @PostMapping("list")
    public Result<List<Room>> getList(@RequestBody Room room){
        return Result.success(roomService.getList(room));
    }


    @ApiOperation("入住")
    @PostMapping("checkIn")
    public Result checkIn(@RequestBody RoomDto roomDto){
        return Result.success(roomService.checkIn(roomDto));
    }


    @ApiOperation("退房")
    @PostMapping("checkOut")
    public Result CheckOut(@RequestBody RoomDto roomDto){
        return Result.success(roomService.checkOut(roomDto));
    }

    @ApiOperation("入住详情")
    @GetMapping("checkInfo/{id}")
    public Result<User> CheckInfo(@PathVariable("id") String id){
        return Result.success(roomService.CheckInfo(id));
    }


    @ApiOperation("房子测试")
    @GetMapping("/test")
    public  Result test(){
        return Result.success(roomService.test());
    }

}
